package com.sky.controller.admin;

import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

/**
 * 店铺相关的接口（管理端）
 */
@RestController("adminRestController")
@RequestMapping("/admin")
@Slf4j
@Api(tags = "店铺相关接口")
public class ShopContoller {
    public static final String SHOP_STATUS = "shopStatus";
    @Autowired
    private RedisTemplate redisTemplate;

    @PutMapping("/shop/{status}")
    @ApiOperation("设置店铺状态")
    public Result setShopStatus(@PathVariable Integer status){
        log.info("开始设置店铺状态{}",status==1?"营业中":"打烊中");
        //这里使用redis存储状态数据
        redisTemplate.opsForValue().set(SHOP_STATUS,status);
        return Result.success();
    }

    @GetMapping("/shop/status")
    @ApiOperation("获取店铺状态")
    public Result getShopStatus(){
        log.info("开始获取店铺状态");
        Integer shopStatus = (Integer) redisTemplate.opsForValue().get(SHOP_STATUS);
        return Result.success(shopStatus);
    }
}
